import { createStore } from 'vuex'
import global from '@/store/modules/global.js'
import user from '@/store/modules/user.js'
import cart from '@/store/modules/cart.js'
import cate from '@/store/modules/category.js'
import createPersistedstate from 'vuex-persistedstate'

export default createStore({
  // 全局模块配置
  ...global,
  // 局部模块配置
  modules: {
    user,
    cart,
    cate
  },
  // 配置Vuex的插件
  plugins: [
    // 持久化触发的条件是state发生变化
    createPersistedstate({
      // 存储在缓存中的数据的key
      key: 'erabbit-client-pc-store-128',
      // 需要存储的模块数据
      paths: ['user', 'cart', 'cate']
    })
  ]
})
